"""MxShop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.views.static import serve
from django.contrib import admin
from django.views.generic import TemplateView
import xadmin
from rest_framework.documentation import include_docs_urls
from rest_framework import routers
from rest_framework.authtoken import views
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework_swagger.views import get_swagger_view

# from MxShop.settings import MEDIA_ROOT
from django.conf import settings
# from goods.views_base import GoodsListView
# from goods.views import GoodsListView
from goods.views import (GoodsListViewSet, GoodsCategoryViewSet, HotSearchWordsViewSet,
                         BannerViewSet, IndexCategoryViewSet)
# from goods.views import goods_list
from users.views import SmsCodeViewSet
from users.views import UserViewSet
from user_operation.views import UserFavViewSet, LeavingMessageViewSet, AddressViewSet
from trade.views import ShoppingCartViewSet, OrderViewSet
from trade.views import AlipaiView

router = routers.DefaultRouter()
# 配置goods的url
router.register(r'goods', GoodsListViewSet, base_name="goods")
# 配置goods category的url
router.register(r'categorys', GoodsCategoryViewSet, base_name="categorys")
# 发送手机验证码
router.register(r'codes', SmsCodeViewSet, base_name="codes")
# 用户注册、用户详情等信息
router.register(r'users', UserViewSet, base_name='users')
# 收藏
router.register(r'userfavs', UserFavViewSet, base_name='userfavs')
# 留言
router.register(r'messages', LeavingMessageViewSet, base_name='messages')
# 收获地址
router.register(r'address', AddressViewSet, base_name='address')
# 购物车
router.register(r'shopcarts', ShoppingCartViewSet, base_name='shopcarts')
# 订单相关
router.register(r'orders', OrderViewSet, base_name='orders')
# 轮播图
router.register(r'banners', BannerViewSet, base_name="banners")
# 首页商品系列数据
router.register(r'indexgoods', IndexCategoryViewSet, base_name='indexgoods')

# swagger风格的api文档页
swagger_view = get_swagger_view(title='慕学生鲜API')


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^xadmin/', xadmin.site.urls),

    # 图片的访问路径
    url(r"^media/(?P<path>.*)", serve, {"document_root": settings.MEDIA_ROOT}),
    # 静态文件的代理
    # url(r"^static/(?P<path>.*)", serve, {"document_root": settings.STATIC_ROOT}),

    url(r'^index/', TemplateView.as_view(template_name="index.html"), name='index'),

    # rest-framework相关url,正则部分不能加后面的$
    url(r'^docs/', include_docs_urls(title="慕学生鲜")),
    url(r'^swagger/', swagger_view),  # 设置swagger风格的api文档
    # rest-framework页面的登陆设置
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),

    # drf自带的token认证模式
    url(r'^api-token-auth/', views.obtain_auth_token),
    # jwt的认证接口
    # url(r'^jwt-auth/', obtain_jwt_token),
    url(r'^login/$', obtain_jwt_token),  # 和vue前端的保持一致，这里修改jwt-auth为login
    url(r'^alipay/return/', AlipaiView.as_view(), name="alipay"),  # 和vue前端的保持一致，这里修改jwt-auth为login

    # 第三方登录,注意上面的login/$一定要加$,否则这里面的地址会被截获
    url(r'', include('social_django.urls', namespace='social')),

    # 商品列表页
    # url(r"^goods/$", GoodsListView.as_view(), name="goods_list"),
    # url(r"^goods/$", goods_list, name="goods_list"),
    url(r'^', include(router.urls)),
]
